/*
 * @Author: Wanko
 * @Date: 2024-06-16 09:19:53
 * @LastEditors: Wanko
 * @LastEditTime: 2024-06-29 19:29:43
 * @Description: 
 */
/*
 * @Author: Wanko
 * @Date: 2024-04-05 16:46:35
 * @LastEditors: Wanko
 * @LastEditTime: 2024-06-15 15:15:39
 * @Description:
 */
const mongoose = require('mongoose')
const { Schema, model } = mongoose
const dayjs = require('dayjs')

const userSchema = new Schema({
  __v: { type: Number, select: false, default: false },
  username: { type: String, required: true },
  password: { type: String, required: true, select: false },
  // 头像
  avatar_url: { type: String, default: '' },
  gender: { type: Number, enum: [-1, 0, 1], default: -1 },
  // 简介
  headline: { type: String },

  name: {
    type: String,
    default: function () {
      return this.username // 使用创建用户时的 username 作为默认值
    }
  },
  create_time: {
    type: String,
    default: () => dayjs().format('YYYY-MM-DD HH:mm:ss')
  },
  update_time: {
    type: String
  },
  like_cards: {
    type: [
      {
        type: Schema.Types.ObjectId,
        ref: 'Card'
      }
    ]
  },
  collection_cards: {
    type: [
      {
        type: Schema.Types.ObjectId,
        ref: 'Card'
      }
    ]
  }
})

module.exports = model('User', userSchema)
